package com.androidtestwheightm.wtheightm0;

import android.content.Intent;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private String strheight;
    private EditText et;
    public static String sex="M";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et=(EditText)findViewById(R.id.editText);
        final Button button=(Button)findViewById(R.id.button);
        button.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View view) {
                RadioGroup rg=(RadioGroup) findViewById(R.id.sex);
                strheight=et.getText().toString();
                if(strheight.equals("")){
                    Toast.makeText(MainActivity.this,"身高不能为空",Toast.LENGTH_SHORT).show();
                }
                Double height=Double.parseDouble(strheight);
                rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                        if(i==R.id.man){
                            sex="M";
                        }else{
                            sex="F";
                        }
                    }
                });
                Intent in=new Intent();
                in.setClass(MainActivity.this,OtherActivity.class);
                Bundle bd=new Bundle();
                bd.putDouble("height",height );
                bd.putString("sex",sex);
                in.putExtras(bd);
                startActivity(in);
            }
        });

    }
}
